home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / jpi / map.bas < prev    next >
BASIC Source File  |  1998-01-29  |  19KB  |  473 lines

  1. Attribute VB_Name = "Map"
  2. Public Const SEASON_SUMMER = 1
  3. Public Const MaxSeasons = 1
  4. Public Type TerrainProfile
  5.   GrassSprites As IndexGroup
  6.   WaterSprites As IndexGroup
  7.   RockObjects As IndexGroup
  8.   TreeObjects As IndexGroup
  9.   DebrisObject As IndexGroup
  10.   WaterBorderSprite As String
  11. End Type
  12. Public SeasonProfiles(MaxSeasons) As TerrainProfile
  13. Global Const MapBlockSize = 16
  14. Global Const HalfMapBlockSize = MapBlockSize / 2
  15. Global Const TERRAINTYPE_NOTHING = 0
  16. Global Const TERRAINTYPE_GRASS = 1
  17. Global Const TERRAINTYPE_WATER = 2
  18. Private Type MAPtype
  19.   Width As Integer
  20.   RealWidth As Integer
  21.   Height As Integer
  22.   RealHeight As Integer
  23.   MapName As String
  24.   EpisodeNumber As Integer
  25.   LevelNumber As Integer
  26. End Type
  27. Global BattleMap As MAPtype
  28. Public Const MAXTERRAINOVERLAYS = 12
  29. Private Type GroundBlock
  30.   TerrainType As Integer
  31.   Occupied As Boolean
  32.   OccupyingObject As Integer
  33.   DamageAmount As Integer
  34.   SpriteNumbers(MAXTERRAINOVERLAYS) As Integer
  35.   AnimFrames(MAXTERRAINOVERLAYS) As Integer
  36.   TerrainOverlayAmount As Integer
  37.   Height As Integer
  38.   Friction As Integer
  39. End Type
  40. Global Const MaxMapX = 152
  41. Global Const MaxMapY = 152
  42. Global GroundBlocks(-2 To MaxMapX + 10, -2 To MaxMapY + 10) As GroundBlock
  43. Public Sub ResetMap()
  44. Dim BlankGroundBlock As GroundBlock, BlankBattleMap As MAPtype
  45. For X = 0 To MaxMapX
  46.   For Y = 0 To MaxMapY
  47.     GroundBlocks(X, Y) = BlankGroundBlock
  48.   Next Y
  49. Next X
  50. BattleMap = BlankBattleMap
  51. End Sub
  52. Public Sub LoadSeasonProfiles()
  53. Call FileFunctions.OpenGameFile(File_TerrainProfiles, 1)
  54. Do
  55.   Line Input #1, a$
  56.   If a$ = FILETAG_ENDFILE Then Exit Do
  57.   If a$ = "[TERRAINPROFILEDEF]" Then
  58.     Line Input #1, a$
  59.     Select Case MiscFunctions.GetPropertyValue(a$)
  60.     Case "Summer"
  61.       Season = SEASON_SUMMER
  62.     End Select
  63.     SeasonProfiles(Season).GrassSprites.IndexesActive = 0
  64.     SeasonProfiles(Season).DebrisObject.IndexesActive = 0
  65.     SeasonProfiles(Season).RockObjects.IndexesActive = 0
  66.     SeasonProfiles(Season).TreeObjects.IndexesActive = 0
  67.     SeasonProfiles(Season).WaterSprites.IndexesActive = 0
  68.     Do
  69.       Line Input #1, a$
  70.       If a$ = "[ENDTERRAINPROFILE]" Then
  71.         Exit Do
  72.       End If
  73.       Select Case MiscFunctions.GetPropertyName(a$)
  74.       Case "WaterBorder:"
  75.         SeasonProfiles(Season).WaterBorderSprite = MiscFunctions.GetPropertyValue(a$)
  76.       Case "GrassSprite:"
  77.         SeasonProfiles(Season).GrassSprites.IndexesActive = SeasonProfiles(Season).GrassSprites.IndexesActive + 1
  78.         SeasonProfiles(Season).GrassSprites.Indexes(SeasonProfiles(Season).GrassSprites.IndexesActive) = GetSpriteIndex(MiscFunctions.GetPropertyValue(a$))
  79.       Case "WaterSprite:"
  80.         SeasonProfiles(Season).WaterSprites.IndexesActive = SeasonProfiles(Season).WaterSprites.IndexesActive + 1
  81.         SeasonProfiles(Season).WaterSprites.Indexes(SeasonProfiles(Season).WaterSprites.IndexesActive) = GetSpriteIndex(MiscFunctions.GetPropertyValue(a$))
  82.       Case "RockObject:"
  83.         SeasonProfiles(Season).RockObjects.IndexesActive = SeasonProfiles(Season).RockObjects.IndexesActive + 1
  84.         SeasonProfiles(Season).RockObjects.Indexes(SeasonProfiles(Season).RockObjects.IndexesActive) = Entities.GetClassNum(MiscFunctions.GetPropertyValue(a$))
  85.       Case "TreeObject:"
  86.         SeasonProfiles(Season).TreeObjects.IndexesActive = SeasonProfiles(Season).TreeObjects.IndexesActive + 1
  87.         SeasonProfiles(Season).TreeObjects.Indexes(SeasonProfiles(Season).TreeObjects.IndexesActive) = Entities.GetClassNum(MiscFunctions.GetPropertyValue(a$))
  88.       Case "DebrisObject:"
  89.         SeasonProfiles(Season).DebrisObject.IndexesActive = SeasonProfiles(Season).DebrisObject.IndexesActive + 1
  90.         SeasonProfiles(Season).DebrisObject.Indexes(SeasonProfiles(Season).DebrisObject.IndexesActive) = Entities.GetClassNum(MiscFunctions.GetPropertyValue(a$))
  91.       End Select
  92.     Loop
  93.   End If
  94. Loop
  95. Close #1
  96. End Sub
  97. Sub ChangeBattleMapSize(Width, Height)
  98. BattleMap.Width = Width
  99. BattleMap.Height = Height
  100. BattleMap.RealWidth = Width * MapBlockSize
  101. BattleMap.RealHeight = Height * MapBlockSize
  102. Call GameEngine.Initialize_BattleView
  103. End Sub
  104. Sub GenerateRandomMap(Width, Height, Season, TerrainRandomness, ForestNumber, ForestSize, RandomTreeAmount, LakeNumber, LakeSizes, Rivers, Streams, BoulderAreaNumber, BouldersPerArea, RandomBoulderAmount, DebrisPiles, DebrisPileSize, RandomDebrisAmount, DirtPathAmount, ClearingAmounts, ClearingSize)
  105. Dim TempPos As Point3D, NewPos As Point3D
  106. LevelSettings.AirFriction = 0.01
  107. LevelSettings.GravityAmount = 1
  108. Call ChangeBattleMapSize(Width, Height)
  109. Select Case Season
  110. Case SEASON_SUMMER
  111.   For X = 0 To Width
  112.     For Y = 0 To Height
  113.       GroundBlocks(X, Y).Friction = 1
  114.       GroundBlocks(X, Y).TerrainType = TERRAINTYPE_GRASS
  115.       GroundBlocks(X, Y).Height = Int(5 * Rnd)
  116.     Next Y
  117.   Next X
  118.   For I = 1 To LakeNumber
  119.     LakeX = Int(Width * Rnd)
  120.     LakeY = Int(Height * Rnd)
  121.     LakeSize = LakeSizes + Int((TerrainRandomness * Rnd) - (TerrainRandomness / 2))
  122.     TempPos.X = LakeX
  123.     TempPos.Y = LakeY
  124.     If TempPos.X < 0 Then TempPos.X = 0
  125.     If TempPos.Y < 0 Then TempPos.Y = 0
  126.     If TempPos.X > BattleMap.Width Then TempPos.X = BattleMap.Width
  127.     If TempPos.Y > BattleMap.Height Then TempPos.Y = BattleMap.Height
  128.     
  129.     For LakeDrawYaw = 1 To 360
  130.       LakeSize = LakeSize + Int(3 * Rnd) - 1
  131.       For RadiusLength = 1 To LakeSize
  132.         NewPos = Math.GetPropelCoordinates(TempPos, LakeDrawYaw, 0, RadiusLength)
  133.         If NewPos.X < 0 Then NewPos.X = 0
  134.         If NewPos.Y < 0 Then NewPos.Y = 0
  135.         If NewPos.X > BattleMap.Width Then NewPos.X = BattleMap.Width
  136.         If NewPos.Y > BattleMap.Height Then NewPos.Y = BattleMap.Height
  137.         GroundBlocks(Int(NewPos.X), Int(NewPos.Y)).TerrainType = TERRAINTYPE_WATER
  138.       Next RadiusLength
  139.     Next LakeDrawYaw
  140.   Next I
  141.   
  142.   For I = 1 To RandomTreeAmount
  143.     ForestX = Int(Width * Rnd)
  144.     ForestY = Int(Height * Rnd)
  145.     TempPos.X = ForestX
  146.     TempPos.Y = ForestY
  147.     If TempPos.X < 0 Then TempPos.X = 0
  148.     If TempPos.Y < 0 Then TempPos.Y = 0
  149.     If TempPos.X > BattleMap.Width Then TempPos.X = BattleMap.Width
  150.     If TempPos.Y > BattleMap.Height Then TempPos.Y = BattleMap.Height
  151.     If GroundBlocks(Int(TempPos.X), Int(TempPos.Y)).Occupied = False Then
  152.       If GroundBlocks(Int(TempPos.X), Int(TempPos.Y)).TerrainType = TERRAINTYPE_GRASS Then
  153.         Call SpawnObject(SeasonProfiles(SEASON_SUMMER).TreeObjects.Indexes(1), SIDE_SCENERY, TempPos.X, TempPos.Y, TempPos.Z, 0, 0)
  154.       End If
  155.     End If
  156.   Next I
  157.  
  158.   For I = 1 To RandomBoulderAmount
  159.     BoulderX = Int(Width * Rnd)
  160.     BoulderY = Int(Height * Rnd)
  161.     TempPos.X = BoulderX
  162.     TempPos.Y = BoulderY
  163.     If TempPos.X < 0 Then TempPos.X = 0
  164.     If TempPos.Y < 0 Then TempPos.Y = 0
  165.     If TempPos.X > BattleMap.Width Then TempPos.X = BattleMap.Width
  166.     If TempPos.Y > BattleMap.Height Then TempPos.Y = BattleMap.Height
  167.     If GroundBlocks(Int(TempPos.X), Int(TempPos.Y)).Occupied = False Then
  168.       If GroundBlocks(Int(TempPos.X), Int(TempPos.Y)).TerrainType = TERRAINTYPE_GRASS Then
  169.         Call SpawnObject(SeasonProfiles(SEASON_SUMMER).RockObjects.Indexes(1), SIDE_SCENERY, TempPos.X, TempPos.Y, TempPos.Z, 0, 0)
  170.       End If
  171.     End If
  172.   Next I
  173.  
  174. End Select
  175. Call AddTerrainSprites(Season)
  176. End Sub
  177. Sub AddTerrainSprites(Season)
  178. For X = 0 To MaxMapX
  179.   For Y = 0 To MaxMapY
  180.     GroundBlocks(X, Y).AnimFrames(1) = 1
  181.     GroundBlocks(X, Y).TerrainOverlayAmount = 1
  182.     'Actual Terrain
  183.     Select Case GroundBlocks(X, Y).TerrainType
  184.     Case TERRAINTYPE_GRASS
  185.       GroundBlocks(X, Y).SpriteNumbers(1) = SeasonProfiles(Season).GrassSprites.Indexes(Int(SeasonProfiles(Season).GrassSprites.IndexesActive * Rnd) + 1)
  186.       GroundBlocks(X, Y).AnimFrames(1) = Int((Sprites(GroundBlocks(X, Y).SpriteNumbers(1)).SpriteGroups(1).FrameMax) * Rnd) + 1
  187.     Case TERRAINTYPE_WATER
  188.       GroundBlocks(X, Y).SpriteNumbers(1) = SeasonProfiles(Season).WaterSprites.Indexes(Int(SeasonProfiles(Season).GrassSprites.IndexesActive * Rnd) + 1)
  189.       GroundBlocks(X, Y).AnimFrames(1) = Int(Sprites(SeasonProfile